import 'default-passive-events';

import './styles/tailwind.css';
import '@vant/touch-emulator';
import { createApp } from 'vue';
import App from './App.vue';
import i18n from '@/i18n/index';
import router, { setupRouter } from './router';
import { setupStore } from '@/store';
import { setupNaive, setupDirectives } from '@/plugins';
import DFPageList from '@/components/DFPageList/index.vue';
import DFPageDetail from '@/components/DFPageDetail/index.vue';
import DFDescriptions from '@/components/DFDescriptions/index.vue';
import DFUploadFile from '@/components/DFUploadFile/index.vue';

import DFUploadImage from '@/components/DFUploadImage/index.vue';

// import DFDialogDetail from '@/components/DFDialogDetail/index.vue';
import DFSvgIcon from '@/components/DFSvgIcon/index.vue';

import { AppProvider } from '@/components/Application';
import config from '@/config';
import 'virtual:svg-icons-register';
import DFScanInput from '@/components/DFScanInput/index.vue';

import 'jsoneditor';

const { VUE_APP_NAME } = config;

async function bootstrap() {
  const appProvider = createApp(AppProvider);

  const app = createApp(App);

  app.component('DFPageList', DFPageList);

  app.component('DFUploadFile', DFUploadFile);

  app.component('DFUploadImage', DFUploadImage);

  app.component('DFPageDetail', DFPageDetail);

  app.component('DFDescriptions', DFDescriptions);

  app.component('DFScanInput', DFScanInput);

  app.component('DFFileList', DFScanInput);

  app.component('DFSvgIcon', DFSvgIcon);

  // 语言注册
  app.use(i18n);

  // 事件总线
  const data = reactive({
    machine: null,
    shiftFn: null,
    shiftData: null,
    shiftList: null,
  });
  app.provide('eventData', data);

  // 注册全局常用的 naive-ui 组件
  setupNaive(app);

  // 注册全局自定义组件
  //setupCustomComponents();

  // 注册全局自定义指令，如：v-permission权限指令
  setupDirectives(app);

  // 注册全局方法，如：app.config.globalProperties.$message = message
  //setupGlobalMethods(app);

  // 挂载状态管理
  await setupStore(app);

  //优先挂载一下 Provider 解决路由守卫，Axios中可使用，Dialog，Message 等之类组件
  appProvider.mount('#appProvider', true);

  // 挂载路由
  await setupRouter(app);

  // 路由准备就绪后挂载APP实例
  await router.isReady();

  app.mount('#app', true);

  app.config.globalProperties.$t = i18n.global.t;

  (window as any)[`${VUE_APP_NAME}App`] = app;
}

void bootstrap();
